package com.jindy.module.oaPayApproval.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.oaEvectionApproval.controller.SyOaEvectionController;
import com.jindy.module.oaEvectionApproval.domain.SyOaEvection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.oaPayApproval.domain.SyOaPay;
import com.jindy.module.oaPayApproval.service.ISyOaPayService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 财务付款审批Controller
 * 
 * @author jindy
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/module/oaPayApproval")
public class SyOaPayController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyOaPayController.class);

    @Autowired
    private ISyOaPayService syOaPayService;

    /**
     * 查询财务付款审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaPayApproval:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyOaPay syOaPay)
    {
        startPage();
        List<SyOaPay> list = syOaPayService.selectSyOaPayList(syOaPay);
        return getDataTable(list);
    }

    /**
     * 导出财务付款审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaPayApproval:export')")
    @Log(title = "财务付款审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyOaPay syOaPay)
    {
        List<SyOaPay> list = syOaPayService.selectSyOaPayList(syOaPay);
        ExcelUtil<SyOaPay> util = new ExcelUtil<SyOaPay>(SyOaPay.class);
        util.exportExcel(response, list, "财务付款审批数据");
    }

    /**
     * 获取财务付款审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaPayApproval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syOaPayService.selectSyOaPayById(id));
    }

    /**
     * 新增财务付款审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaPayApproval:add')")
    @Log(title = "财务付款审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyOaPay syOaPay)
    {
        return toAjax(syOaPayService.insertSyOaPay(syOaPay));
    }

    /**
     * 修改财务付款审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaPayApproval:edit')")
    @Log(title = "财务付款审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyOaPay syOaPay)
    {
        return toAjax(syOaPayService.updateSyOaPay(syOaPay));
    }

    /**
     * 删除财务付款审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaPayApproval:remove')")
    @Log(title = "财务付款审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syOaPayService.deleteSyOaPayByIds(ids));
    }

    /**
     * 提交申请
     */
    @Log(title = "财务付款审批", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitApply/{id}")
    @ResponseBody
    public AjaxResult submitApply(@PathVariable Long id) {
        try {
            SyOaPay syOaPay = syOaPayService.selectSyOaPayById(id);
            syOaPayService.submitApply(syOaPay);
        } catch (Exception e) {
            LOGGER.error("财务付款审批提交申请出错",e);
            return error("财务付款审批提交申请出错：" + e.getMessage());
        }
        return success();
    }
}
